<template>
	<div style="width: 100%; height: 100%; position: relative;">
		<div class="container">
			<el-table border :data="tableData" style="width: 100%" :default-sort="{prop: 'date', order: 'descending'}">
				<el-table-column prop="date" label="日期" sortable width="180">
				</el-table-column>
				<el-table-column prop="sort" label="序号" sortable width="180">
				</el-table-column>
				<el-table-column prop="tags" label="标签" sortable width="180">
					<template slot-scope="scope">
						<el-tag style="margin: 0 5px;" v-for="itam in scope.row.tags" type="primary"
							disable-transitions>{{itam}}</el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="name" label="名称" width="240">
				</el-table-column>
				<el-table-column prop="price" label="售价" sortable width="180">
				</el-table-column>
				<el-table-column prop="volume" label="销量" sortable width="180">
				</el-table-column>
				<el-table-column prop="state" label="状态" width="180">
					<template slot-scope="scope">
						<el-tag :type="scope.row.state == true ? 'success' : 'info'"
							disable-transitions>{{scope.row.state==true ? '上架' : "下架"}}</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作">
					<template slot-scope="scope">
						<el-button size="mini" @click="$emit('fuc','goodupdate',scope.row._id)">编辑</el-button>
						<el-button size="mini" type="danger"
							>删除</el-button>
					</template>
				</el-table-column>
			</el-table>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				tableData: []
			};
		},
		created() {
			let _id = '6625e7c9fe975f74409546d6'
			let col = uniCloud.importObject('indexObj', {
				customUI: true
			})
			let alltag = []
			col.getImagepackTag().then((rea) => {
				console.log(rea.data.data)
				alltag = rea.data.data
				col.getgoodsPicture(_id).then((res) => {
					console.log(res.data.data)
					res.data.data.map((n, m) => {
						let date = n.create_date
						let tags = []
						n.picture_type.map(n => {
							alltag.map(j => {
								if (j._id == n) {
									tags.push(j.name)
								}
							})
						})
						console.log(tags)
						this.tableData.push({
							"date": `${date[0]}${date[1]}${date[2]}${date[3]}-${date[4]}${date[5]}-${date[6]}${date[7]}`,
							"sort": n.sort,
							"tags": tags,
							"name": n.name,
							"price": n.price,
							"volume": n.volume,
							"state": n.state,
							"_id":n._id
						})
					})
				})
			})


		},
		methods: {
			formatter(row, column) {
				return row.address;
			}
		}
	}
</script>

<style lang="scss">
	.container {
		margin: 0;
		padding: 0;
		background-color: #fff;
		width: 100%;
		height: 97%;
		overflow-y: auto;
		overflow-x: hidden;

	}
</style>